package com.app.mycomposedemo.ui.components


import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DateRange
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.Person
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import com.app.mycomposedemo.data.NavigationItemData
import com.app.mycomposedemo.ui.theme.Blue700

@Composable
fun BottomNavigationComp(currentIndex:Int ,updateClickedIndex: (Int) -> Unit) {

    val navigationItems = listOf(
        NavigationItemData(Icons.Default.Favorite, "学习"),
        NavigationItemData(Icons.Default.DateRange, "任务"),
        NavigationItemData(Icons.Default.Person, "我的")
    )


    BottomNavigation(
        backgroundColor = Color.White,
        modifier = Modifier.navigationBarsPadding()
    ) {
        navigationItems.forEachIndexed { index, item ->
            BottomNavigationItem(
                selected = currentIndex == index,
                onClick = { updateClickedIndex(index) },
                icon = { Icon(imageVector = item.icon, contentDescription = null) },
                label = { Text(text = item.label) },
                selectedContentColor = Blue700,
                unselectedContentColor = Color.Gray
            )
        }
    }
}

@Preview
@Composable
fun BottomNavigationCompPreview() {
    BottomNavigationComp(0){}
}

